package vip

import (
	"github.com/leanote/leanote/app/controllers"
	"github.com/revel/revel"
	"github.com/leanote/leanote/app/info"
	"strconv"
	"github.com/leanote/leanote/app/service"
)

var userServer *service.UserService

//测试用
type Vip struct {
	controllers.BaseController
}

func init() {
	userServer = service.UserS
}

func (v Vip)User(email string) revel.Result  {

	user:=userServer.GetUserInfoByName(email)
	if user.UserId != ""{
		re:=info.NewApiRe()
		re.Success(user)
		return v.RenderJson(re)
	}else {
		re:=info.NewApiRe()
		re.Ok = false
		re.Msg = "用户"+email+"不存在"
		return v.RenderJson(re)
	}


}

func (v Vip) List() revel.Result  {
	re:=info.NewApiRe()
	re.Ok = true
	re.Msg = "vip"
	return v.RenderJson(re)
}

func (v Vip) Test() revel.Result  {
	re:=info.NewApiRe()
	re.Ok = true
	re.Msg = "test route"
	return v.RenderJson(re)
}

//http://127.0.0.1:9000/vip/isvip?id=36

func (v Vip) IsVip(id int) revel.Result  {

	re:=info.NewApiRe()
	re.Ok = true
	re.Msg = strconv.Itoa(id)
	return v.RenderJson(re)
}

func (v Vip)NewVip() revel.Result{
	re:=info.NewApiRe()
	aa:=info.Vip{Level:1,UserId:"lxy"}
	ok:=vipService.Insert(aa)
	re.Ok = ok
	if ok {
		re.Msg = "success"
	}else {
		re.Msg = "fail"
	}
	return v.RenderJson(re)
}



